package cn.yyljlyy.blog.frontend.controller;

import cn.yyljlyy.blog.common.Consts;
import cn.yyljlyy.blog.common.utils.StringUtils;
import cn.yyljlyy.blog.frontend.service.ContextService;
import cn.yyljlyy.blog.frontend.service.OptionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @function: cn.yyljlyy.blog.frontend
 * @author: LiJian
 * @data: 2016年11月17日17：03.
 */
@Controller
@RequestMapping(value = "/")
public class IndexCtrl {
    private static final Logger logger = LoggerFactory.getLogger(IndexCtrl.class);

    @Autowired
    private OptionService optionService;
    @Autowired
    private ContextService contentService;

    @RequestMapping("/")
    public String index(Model model,String page){

        model.addAttribute("list",contentService.getIndexList());
        String title = optionService.findValue("seo_index_title");
        String keywords = optionService.findValue("seo_index_keywords");
        String description = optionService.findValue("seo_index_description");

        if (StringUtils.isNotBlank(title)) {
            model.addAttribute(Consts.ATTR_GLOBAL_WEB_TITLE, title);
        }
        if (StringUtils.isNotBlank(keywords)) {
            model.addAttribute(Consts.ATTR_GLOBAL_META_KEYWORDS, keywords);
        }
        if (StringUtils.isNotBlank(description)) {
            model.addAttribute(Consts.ATTR_GLOBAL_META_DESCRIPTION, description);
        }
        if (StringUtils.isBlank(page)){
            return "index";
        }else {
            return "page-" + page;
        }
    }

    @RequestMapping("/jos_guid.txt")
    public String set(Model model,String page){
        return "jos";
    }

}
